@model iMyRestaurent.Models.ChangePasswordModel
@section import {
    @NoCache.Instance.Css(Url, "~/Content/account.css")
}
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "iMyRestaurant - Change password";

    switch (Model.Mode)
    {
        case iMyRestaurent.Shared.Mode.Create:
            ViewBag.NextAction = Url.Action("Create", "Profile");
            break;
        default:
            ViewBag.NextAction = Url.Action("Index", "Summary");
            break;
    }
}
<div class="landing-container">
    <div class="image-left">
    </div>
    <div class="image-right">
    </div>
    <div id="top-space">
    </div>
    <div class="logo">
    </div>
    <div id="version">
        Version 1.3.83</div>
    <div id="powered-by">
        <span>Powered by </span><span class="vendor-name">iMyVenue applications</span>
    </div>
    <div id="description">
        A major step forward in managing your restaurant and getting customers<br />
        to make table reservations from Smartphone devices or your website.
    </div>
    <div class="opacity-box center-box clearfix" id="form">
        <form>
        <div class="center-box" id="table-form">
            <div style="text-align: center; padding-bottom: 20px;">
                <span>Please change your password now</span>
            </div>
            <div class="clearfix">
                <div class="change-password-title">
                    <span>Old password</span>
                </div>
                <div class="change-password-input">
                    @Html.PasswordFor(x => x.OldPassword)
                </div>
            </div>
            <div class="clearfix">
                <div class="change-password-title">
                    <span>New password</span>
                </div>
                <div class="change-password-input">
                    @Html.PasswordFor(x => x.NewPassword)
                </div>
            </div>
            <div class="clearfix">
                <div class="change-password-title">
                    <span>Retype new password</span>
                </div>
                <div class="change-password-input">
                    @Html.PasswordFor(x => x.RetypeNewPassword)
                </div>
            </div>
            <input type="submit" class="image-button button-change center-box" value="" />
        </div>
        </form>
        <form action="@ViewBag.NextAction" method="post" id="next">
        <input type="hidden" name="LocationID" value="@Model.SummaryLocationID" />
        <input type="hidden" name="Date" value="@Model.SummaryDate" />
        </form>
    </div>
</div>
@section footer {
    @if (Model.Mode == iMyRestaurent.Shared.Mode.Edit)
    {
        <div>
            <form action="@Url.Action("Index", "Summary")" method="post">
            <input type="hidden" name="LocationID" value="@Model.SummaryLocationID" />
            <input type="hidden" name="Date" value="@Model.SummaryDate" />
            <input type="submit" value="" class="image-button button-back" />
            </form>
        </div>
    }
}
@section script {
    <script type="text/javascript">
        $(function () {
            $('.button-change').click(function () {
                showProgressDialog('Changing password');

                $.ajax({
                    type: 'post',
                    url: '/Account/ChangePasswordAPI',
                    data: {
                        OldPassword: $('input[name="OldPassword"]').val(),
                        NewPassword: $('input[name="NewPassword"]').val(),
                        RetypeNewPassword: $('input[name="RetypeNewPassword"]').val()
                    },
                    success: function (response) {
                        if (response.IsSucceed) {
                            showProgressDialog('Your password has been changed successfully!');
                            $('form#next').submit();
                        } else {
                            hideProgressDialog();

                            // focus to submit control so the virtual keyboard is hidden
                            $('.button-change').focus();
                            MessageBox.show({
                                message: [response.Message],
                                buttons: {
                                    ok: function () {
                                    }
                                }
                            });
                        }
                    },
                    error: function () {
                        hideProgressDialog();

                        Utils.showError();
                    }
                });

                return false;
            });
        });        
    </script>
}
